package net.csdra.libraryborrowing.domain.book;

import net.csdra.libraryborrowing.domain.CMSJpaRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by msf on 2017/10/9.
 */
public interface BookInfoRepository extends CMSJpaRepository<BookInfo, String> {

    @Query("select b from BookInfo b where b.name like ?1 or b.author like ?1")
    Page<BookInfo> searchBookByKey(String key, Pageable pageable);

    @Query("select b from BookInfo  b, BookStorageBox s where s.metaId = ?1 and s.bookInfoId = b.id")
    List<BookInfo> getBookInfoByBookStorageBox(String userId);

    @Query("select b from BookInfo b, UserBorrow  u where u.metaId = ?1 and u.state = ?2 and u.bookInfoId = b.id ")
    Page<BookInfo> getBookInfoByUserBorrow(String userId, String userBorrowState, Pageable pageable);

    @Query("select b from BookInfo b where b.categoriees in ?1")
    Page<BookInfo> getBookListByCategory(List<String> categories, Pageable pageable);
}
